<%
  rows_to_assign = selected_rows.select{ |k, v| v[:assigned] == "true" }
  rows_to_unassign = selected_rows.select{ |k, v| v[:assigned] == "false" }
%>
<div class="modal-header">
  <button type="button" class="close self-start" data-dismiss="modal" aria-label="Close">
    <i class="sn-icon sn-icon-close"></i>
  </button>
  <h4 class="modal-title">
    <% if downstream %>
        <%= t('my_modules.modals.update_repository_record.title_downstream',
             repository_name: repository.name) %>
    <% else %>
      <%= t('my_modules.modals.update_repository_record.title',
           repository_name: repository.name,
           my_module_name: my_module.name) %>
    <% end %>
  </h4>
</div>
<div class="modal-body">
  <% if downstream %>
    <p class="description-1"><%= t('my_modules.modals.update_repository_record.message_downstream_1', size: selected_rows.values.count) %></p>
    <p class="description-2 hidden"><%= t('my_modules.modals.update_repository_record.message_downstream_2') %></p>
  <% else %>
    <p class="description"><%= t('my_modules.modals.update_repository_record.message', size: selected_rows.values.count) %></p>
  <% end %>
  <div class="rows-list-container <%= 'multiple' if rows_to_assign.values.any? && rows_to_unassign.values.any? %>">
    <% if rows_to_assign.values.any? %>
      <div class="rows-to-assign">
        <p class="header">
          <i class="sn-icon sn-icon-new-task"></i>
          <%= t('my_modules.modals.update_repository_record.newly_assigned_items') %>
        </p>
        <ul class="rows-list">
          <% rows_to_assign.each do |row_id, row| %>
            <li><%= row[:row_name] %></li>
          <% end %>
        </ul>
      </div>
    <% end %>
    <% if rows_to_unassign.values.any? %>
      <div class="rows-to-unassign">
        <p class="header">
          <i class="sn-icon sn-icon-minus"></i>
          <%= t('my_modules.modals.update_repository_record.items_will_be_removed') %>
        </p>
        <ul class="rows-list">
          <% rows_to_unassign.each do |row_id, row| %>
            <li><%= row[:row_name] %></li>
          <% end %>
        </ul>
      </div>
    <% end %>
  </div>
  <% if downstream %>
    <div class='my-modules-to-assign hidden'>
      <% visible_modules = 0
         downstream_modules = my_module.downstream_modules
         downstream_modules.each do |m| %>
        <% if can_assign_my_module_repository_rows?(m) %>
          <div class='my-module-to-assign'>
            <% if m == my_module %>
              <span class="current-task"><%= t('my_modules.modals.assign_repository_record.current_task') %></span>
            <% end %>
            <%= m.name %>
          </div>
          <% visible_modules += 1 %>
        <% end %>
      <% end %>
    </div>
    <% if visible_modules != downstream_modules.size %>
      <div class="hidden-my-modules hidden">
        <i class="fas fa-exclamation-triangle"></i>
        <%= t('my_modules.modals.assign_repository_record.hidden_tasks', size: (downstream_modules.size - visible_modules)) %>
      </div>
    <% end %>
  <% end %>
</div>
<div class="modal-footer">
  <div class="sci-btn-group">
    <a class="btn btn-secondary" data-dismiss="modal">
      <%= t('general.cancel') %>
    </a>
    <% if downstream %>
      <a class="btn btn-primary next-step" >
        <%= t('my_modules.modals.update_repository_record.next') %>
      </a>
      <a class="btn btn-primary downstream-action hidden" >
        <%= t('my_modules.modals.update_repository_record.task_and_downstream') %>
      </a>
    <% else %>
      <a class="btn btn-primary task-action">
        <%= t('my_modules.modals.update_repository_record.task') %>
      </a>
    <% end %>
  </div>
</div>
